package com.cars.hdfs.config;

import org.apache.hadoop.fs.FileSystem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @ClassName: HDFSConfig
 * @Description: HDFS配置类
 * @author: caoqianfan
 * @date: 2023/9/4 9:05
 */
@Configuration
public class HDFSConfig {

    @Value("${hadoop.fs.defaultFS}")
    private String hdfsUri;

    @Bean
    public FileSystem fileSystem() throws IOException {
        System.setProperty("HADOOP_USER_NAME", "root");
        org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
        configuration.set("fs.defaultFS", hdfsUri);
        return FileSystem.get(configuration);
    }

}